#include<functional>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<netinet/in.h>

#include<thread>
#include<chrono>

#include<pthread.h>

#include"timer.h"
#include"sender.h"
#include"receiver.h"

using namespace std;

#define BUFF_LINE 512
#define BUFF_LINE_2 1024




/***************************************
		   Function Main	
***************************************/

int main(int argc, char **argv)
{

	SenderThread senderThread;
	ReceiverThread receiverThread;

	SenderController senderController;
	senderController.sender_install( &senderThread.sender );

	ReceiverController receiverController;
	receiverController.udpCs_install( &receiverThread.udpCs );

	TimerThread timeThread_sender(chrono::seconds(20), senderController.sender_stop_sender);
	TimerThread timeThread_receiver(chrono::seconds(10), receiverController.udpCs_stop_receiver);

	timeThread_sender.run_independent_timer();
	timeThread_receiver.run_independent_timer();

	receiverThread.run_independent_receiver();
	senderThread.run_independent_sender();


	timeThread_sender.wait_for_timer();
	timeThread_receiver.wait_for_timer();

	senderThread.wait_for_sender();
	receiverThread.wait_for_receiver();

	

	return 0;
}

